import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Person bob = new Person(new Certificate(310), "Bob", 30000);
        Car car1 = new Car("001","red",50000, bob);
        bob.addCar(car1);

        Person tom = new Person(new Certificate(210), "Tom", 70000);
        Car car2 = new Car("003", "white", 25000, tom);
        tom.addCar(car2);

        Person king = new Person(new Certificate(245), "King", 60000);
        Car car3 = new Car("005", "white",18000, king);
        Car car4 = new Car("045", "red", 58000, king);
        king.addCar(car3);
        king.addCar(car4);

        //market add car
        Market.addCar(car1);
        Market.addCar(car2);
        Market.addCar(car3);
        Market.addCar(car4);

        //market add person
        Market.addPerson(bob);
        Market.addPerson(tom);
        Market.addPerson(king);
    
        //-----debug info---------->>
        System.out.println("market initial:");
        debugInfo();
        //-----debug info-------------<<

        Market.sellCar(bob, null, tom); 
        Market.sellCar(king, car3, bob);

        //-----debug info---------->>
        System.out.println("market result:");
        debugInfo();
        //-----debug info-------------<<
    }
    
    public static void debugInfo(){
        System.out.println("cars:");
        for(Car c : Market.cars){
            System.out.println("carId:"+c+" owner:"+c.getOwner());
        }
        System.out.println("persons:");
        for(Certificate cer: Market.people.keySet()){
            System.out.println(Market.people.get(cer) + " cash:"+ Market.people.get(cer).getCash()+ " cars"+ Market.people.get(cer).getCars());
        }
    }

}
